{% extends "osr-theme-w/pages/based/based_no_head.html" %}
{% block title %}{{_("找回密码")}}-{% endblock %}
{% block content %}
<div id="app" v-cloak>
     <div class="osr-full-bg-cover" :style="'background:no-repeat center center fixed;'"></div>
    <div class="osr-login-page row col-xs-12 osr-div-center osr-edit-page">
    <p class="text-center">
        <a href="/">
            <img class="osr-logo" src="{{g.site_global.site_config.LOGO_IMG_URL}}" alt="Logo">
        </a>
    </p>
    <div class="form-group">
      <input name="email" id="email" class="form-control osr-input input-lg osr-hollow-color" type="email" v-model="email"
             placeholder="{{_('电子邮箱')}}"
             data-bv-emailAddress="true" data-bv-emailAddress-message="{{_('邮箱地址不合法')}}"
            data-bv-notempty-message="{{_('邮箱地址不能为空')}}" required
             placeholder="{{_('电子邮箱')}}"  required/>
    </div>
    <div class="form-group">
      <input name="password" id="password" class="form-control osr-input input-lg osr-hollow-color" type="password" v-model="password"
             minlength="8" placeholder="{{_('输入密码')}}"
             data-bv-notempty-message="{{_('至少8个字符')}}"
             data-bv-stringLength-message="{{_('至少8个字符')}}" required/>
    </div>
    <div class="form-group">
      <input name="password2" id="password2" class="form-control osr-input input-lg osr-hollow-color" type="password" v-model="password2"
             placeholder="{{_('再次输入密码')}}"
             data-bv-identical="true"
             data-bv-notempty-message="{{_('至少8个字符')}}"
             data-bv-identical-message="{{_('前后密码不一致')}}"
             data-bv-identical-field="password" required/>
    </div>

    {% include 'osr-theme-w/pages/module/_send_code.html' %}

    <div class="form-group">
        <button v-on:click="reset()" class="btn-block btn osr-btn btn-success osr-submit-btn btn-lg">
            {{_('重设密码')}}
        </button>
    </div>

    <div class="form-group osr-color-success osr-white-text">
        <i class="fa fa-sign-in"></i>
        <a class="osr-white-text" href="/sign-in">{{_("回到登录")}}</a>
    </div>

    <div class="form-group">
        {% include 'osr-theme-w/pages/module/_no_header_select_lan.html' %}
    </div>
    </div>
</div>
<script>
    var vue = new Vue({
      el: '#app',
      delimiters:['{[', ']}'],
      data: {
        email:'',
        password: '',
        password2: '',
        email_code:"",
        //_send_code.html需要参数
        send_code_to_exist_account:1,
        img_code_url_obj:{},
        img_code_url:"",
        img_code:""
      }
    })

    // 页面一加载完就自动执行
    $(document).ready(function(){
        (function($) {
            if ($.AMUI && $.AMUI.validator) {
            // 增加多个正则
            $.AMUI.validator.patterns = $.extend($.AMUI.validator.patterns, {
                 osrEmail:/^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
                 osrPassword:/^(?!(?:\d+|[a-zA-Z]+)$)[\da-zA-Z]{8,}$/
            });
            // 增加单个正则
            //$.AMUI.validator.patterns.osrEmail = /^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
        }
        })(window.jQuery);

        var result = osrHttp("GET","/api/global");
        result.then(function (r) {
            if(r.data.is_authenticated){
                window.location.href = "/";
            }
        })
    });

   function reset(){
        formValidate();
        var d = {   email:vue.email,
                    password:vue.password,
                    password2:vue.password2,
                    email_code:vue.email_code,
                }
        // 提交数据
        osrHttp("PUT","/api/account/password/retrieve", d);
   }

</script>
{% endblock %}

